package com.xm.web.controller.system;

import com.xm.common.entity.R;
import com.xm.web.entity.request.RolePermissionRequest;
import com.xm.web.entity.request.RoleRequest;
import com.xm.web.entity.response.RoleResponse;
import com.xm.web.service.ITbRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 角色
 *
 * @author yousj
 * @since 2021/8/28
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys/role")
@Api(tags = "角色")
public class RoleController {

    private final ITbRoleService roleService;

    @ApiOperation(value = "列表")
    @GetMapping("/list")
    public R list(String roleName) {
        return R.isOk(roleService.list(roleName));
    }

    @ApiOperation(value = "详情")
    @GetMapping("/details/{id}")
    public R<RoleResponse> details(@PathVariable Integer id) {
        return R.isOk(roleService.getById(id));
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public R add(@RequestBody RoleRequest request) {
        return R.isOk(roleService.add(request));
    }

    @ApiOperation(value = "修改角色")
    @PostMapping("/update")
    public R update(@RequestBody RoleRequest request) {
        return R.isOk(roleService.update(request));
    }

    @ApiOperation(value = "修改权限")
    @PostMapping("/updatePermissions")
    public R updatePermissions(@RequestBody RolePermissionRequest request) {
        return R.isOk(roleService.updatePermissions(request));
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        return R.isOk(roleService.removeById(id));
    }

}
